(function($){
    function formResult(msg, state) {
        layer.closeAll();
        if(state == 0) {
            layer.alert(msg, {icon: 5});
        }else{
            location.reload(true);
        }
    }
    function init(){
        $('.table tbody tr').click(function () {
            var card_id = $(this).find('[name="id"]').val();
            layer.prompt({
                formType: 0,
                title: '请输入退款金额'
            }, function(value, index, elem){
                var r = /^-?\d+$/ ;
                var s = /^[0-9]+\.[0-9]{0,2}$/;
                if($.trim(value) == ''){
                    layer.alert('不能为空', {icon: 2});
                } else if(!r.test(value)&&!s.test(value)) {
                    layer.alert('请输入退款金额', {icon: 2});
                } else {
                    $.post(
                        '/business/financial/cashier?action=healthcardrefund',
                        {card_id:card_id,amount:value},
                        function(data){
                            if(data.state == 1) {
                                layer.alert('退款成功', {icon: 1});
                                parent.location.reload(true);

                            } else {
                                layer.alert(data.message, {icon: 1});
                                parent.location.reload(true);
                            }
                        },
                        'json'
                    )

                }

            },
            function(index){
                parent.location.reload(true);
            }
        );
        })
    }

    $(function() {
        layer.config({
            extend: 'extend/layer.ext.js'
        });
        window.formResult = formResult;
        init();

    })
})(jQuery);